<div class="yiiForm">

<?php

if (isset($meeting) && $meeting->hasErrors()) {
	echo "Impossible de sauvegarder le premier rendez vous:";
	echo CHtml::errorSummary($meeting);
}

global $types, $meeting_date; 
$types = array(ProjectTopic::STEP => "step", ProjectTopic::TOPIC => "topic");
$meeting_date = $meeting->meeting_date;

$this->widget('application.components.RequiredMessage');

echo Yii::t('views', 'Topics available');

function display_topics($page, $model, $odd, $topics) {
	global $types, $meeting_date;

	if ($topics == null || ! is_array($topics))
		return $odd;
		
	echo "<ul class=\"topic_tree\">";
	foreach ($topics as $topic) {
		echo "<li id=\"" . $topic->key . "\"><div class=\"item " . $types[$topic->item_type] . "_" . ($odd ? 'odd' : 'even') . "\">\n  ";
		echo CHtml::activeHiddenField($topic, "[".$topic->key."]id");

		if ($topic->parent_key != null && $topic->parent_key != "")
			echo CHtml::activeHiddenField($topic, "[".$topic->key."]parent_key");
		
		echo "  <span id=\"label_" . $topic->key . "\" class=\"label\">" . $topic->label . "</span>&nbsp;\n";
		// TODO insert image
		$image = CHtml::image("/images/comment.png", "Commentaires");
		if (isValid($topic->objective, $topic->objective_date))
			$image = CHtml::image("/images/target.png", "Défini comme objectif");
		if (isValid($topic->owner_validation, $topic->owner_validation_date))
			$image = CHtml::image("/images/progress.gif", "Validé par le porteur");
		if (isValid($topic->adviser_validation, $topic->adviser_validation_date))
			$image = CHtml::image("/images/confirm.png", "Validé par le conseiller");
			
		echo "  <span id=\"label_" . $topic->key . "\" class=\"user_inputs\"><a class='dlg_link'>$image</a></span>";
		echo "  <div id=\"comment_" . $topic->key . "\" class=\"comment_area\">\n    ";
		
		$optscb = array('value' => ProjectTopic::YES, 'uncheckValue' => ProjectTopic::NO, 'class' => 'validation_cb adviser_validation', 'disabled' => 'disabled');
		if ($topic->adviser_validation == ProjectTopic::INHERITS) {
			$optscb['value'] = ProjectTopic::INHERITS;
		}
		echo CHtml::activeCheckBox($topic, "[".$topic->key."]adviser_validation", $optscb);
		echo CHtml::activeLabel($topic, "[".$topic->key."]adviser_validation") . "\n    ";
		
		$optscb = array('value' => ProjectTopic::YES, 'uncheckValue' => ProjectTopic::NO, 'class' => 'validation_cb owner_validation', 'disabled' => 'disabled');
		if ($topic->owner_validation == ProjectTopic::INHERITS) {
			$optscb['value'] = ProjectTopic::INHERITS;
		}
		echo CHtml::activeCheckBox($topic, "[".$topic->key."]owner_validation", $optscb);
		echo CHtml::activeLabel($topic, "[".$topic->key."]owner_validation") . "\n    ";
		
		$opts = array();
		$opts['rows'] = '5';
		$opts['cols'] = '75';
		
		if ($topic->adviser_validation == ProjectTopic::YES || $topic->owner_validation == ProjectTopic::YES) {
			echo "<div id=\"validation_comment_" . $topic->key . "\" class=\"validation_area\">";
			echo "<b>" . CHtml::activeLabel($topic, "[".$topic->key."]validation_comment") . "</b><br />\n    ";
			echo "<div class='textarea'>" . $topic->validation_comment. "&nbsp;</div>\n      ";
						echo "</div>";
		}
		
		$optscb = array('value' => ProjectTopic::YES, 'uncheckValue' => ProjectTopic::NO, 'class' => 'objective_cb objective', 'disabled' => 'disabled');
		if ($topic->objective == ProjectTopic::INHERITS) {
			$optscb['value'] = ProjectTopic::INHERITS;
		}
		echo CHtml::activeCheckBox($topic, "[".$topic->key."]objective", $optscb);
		echo CHtml::activeLabel($topic, "[".$topic->key."]objective") . "\n    ";
		
		if ($topic->objective == ProjectTopic::YES) {
			echo "    <div id=\"objective_comments_" . $topic->key . "\" class=\"objective_area\">\n      ";
			echo  "<b>" . CHtml::activeLabel($topic, "[".$topic->key."]objective_needs") . "</b><br />\n      ";
			echo "<div class='textarea'>" . $topic->objective_needs. "&nbsp;</div>\n      ";
						
			echo "<b>" . CHtml::activeLabel($topic, "[".$topic->key."]objective_contacts") . "</b><br />\n      ";
			echo "<div class='textarea'>" . $topic->objective_contacts. "&nbsp;</div>\n      ";
						echo "</div>";
		}
		
		echo "  </div>\n";
		echo "</div>\n";

		echo CHtml::errorSummary($topic);

		//global $iiii;
		//$iiii++;
		//if ($iiii <= 1)
		display_topics($page, $model, !$odd, $topic->children);
		//$iiii--;
		
		echo "</li>\n";
		$odd = !$odd;
	}
	echo "</ul>";
	return $odd;
}


function isValid($status, $date){
	global $meeting_date;
	return $status != ProjectTopic::NO && $date != null && $date <= $meeting_date;
}

//global $iiii;
//$iiii = 0;
echo "<div id=\"topics_tree\">";
display_topics($this, $model, true, $roots);
echo "</div>";
?>

</div>

